<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateDeviceAccountsTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('device_accounts', function(Blueprint $table)
		{
			$table->integer('id', true);
			$table->string('account', 170)->unique('da_acnt')->comment('账号名称');
			$table->string('password')->comment('账号的密码');
			$table->integer('customer_id')->default(0)->comment('关联customers表的id');
			$table->integer('store_id')->default(0)->comment('关联stores 表的id');
			$table->integer('device_id')->default(0)->comment('关联devices表的id (售出的设备才有)');
			$table->integer('skin_detector_id')->nullable()->default(0)->comment('关联skin_detectors表的 id （废弃，改成多对多）');
			$table->integer('sell_device_id')->default(0)->comment('关联sell_devices表的 id');
			$table->string('device_name')->nullable()->comment('设备的名称和型号');
			$table->string('uuid')->nullable()->comment('设备唯一编码 ，后台添加');
			$table->string('reset_token')->nullable()->comment('重置密码token');
			$table->text('remember_token', 65535)->nullable()->comment('jwt 的登录token');
			$table->string('longitude')->nullable()->comment('经度');
			$table->string('latitude')->nullable()->comment('纬度');
			$table->boolean('is_debug')->default(0)->comment('调试状态：不限制UUID绑定登录');
			$table->boolean('enabled')->default(1)->comment('账号是否可用');
			$table->string('language', 50)->default('zh-CN')->comment('语言设置');
			$table->dateTime('last_login_at')->default('1970-01-02 00:00:00');
			$table->dateTime('last_active_at')->default('1970-01-02 00:00:00');
			$table->string('location')->nullable();
			$table->integer('alive_seconds')->unsigned()->default(0);
			$table->timestamps();
		});
	}


	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('device_accounts');
	}

}
